<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/12/16
 * Time: 10:17
 */

namespace app\admin\controller;


use think\Db;

class Classinte extends Base
{
    /**
     * 课程兑换码列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $user_name = input('user_name');
            $type = input('type');
            $user_phone = input('user_phone');
            $where = [];
            if(isset($user_name) && $user_name != ''){
                $where['user_username'] = ['like', '%' . $user_name . '%'];
            }
            if(isset($user_phone) && $user_phone != ''){
                $where['user_phone'] = ['like', '%' . $user_phone . '%'];
            }
            if(isset($type) && $type != ''){
                $where['ci_type'] = $type;
            }
            
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 100;
            $count = Db::name('class_integral')
                ->join('up_u_user', 'user_id = ci_user_id', 'LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('class_integral')
                ->join('up_u_user', 'user_id = ci_user_id', 'LEFT')
                ->where($where)
                ->field('ci_id, user_username, user_phone, ci_integral, ci_type, ci_time')
                ->order('ci_time desc')
                ->page($Nowpage,$limits)
                ->select();
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
}